﻿using ModuleBase;

namespace ThreadSleep
{
    public class ThreadSleep : ModuleBase.ModuleBase
    {
        private int _parameter1 = 500;
        public int Parameter1
        {
            get => _parameter1;
            set
            {
                if (_parameter1 != value)
                {
                    _parameter1 = value;
                    OnPropertyChanged(nameof(Parameter1));
                }
            }
        }
        public override Dictionary<string, object> GetProperties()
        {
            return new Dictionary<string, object>
            {
                { "延时(ms)", Parameter1 },
            };
        }

        public ThreadSleep()
        {
            Name = "延时";

            DisplayNameToPropertyNameMap = new Dictionary<string, string>
            {
                { "延时(ms)", nameof(Parameter1) },
            };
        }

        public override bool Execute()
        {
            Thread.Sleep(Parameter1);           
            return true;
        }

        public override async Task<bool> ExecuteAsync()
        {
            var result = await Task.Run(() => Execute());
            return result;
        }

        public override void Initialize()
        {

        }

        public override string Description => "延时模块：用于流程中插入指定毫秒数的延时等待。";
    }
}
